﻿using System.Linq;
using System.Data.Objects;
using System.Data.Metadata.Edm;

namespace ControlePonto.Extensions
{
    public static class ObjectContextExtensions
    {
        public static string GetEntitySetName<TEntity>(this ObjectContext context) where TEntity: class
        {

            var container = context.MetadataWorkspace.GetEntityContainer(context.DefaultContainerName, DataSpace.CSpace);
            string entitySetName = (from meta in container.BaseEntitySets
                                    where meta.ElementType.Name == typeof(TEntity).Name
                                    select meta.Name).FirstOrDefault();
            return entitySetName;
        }
    }
}